package cn.shuibo.controller;

import cn.shuibo.advice.AdviceLocalThread;
import cn.shuibo.advice.EncryptResponseBodyAdvice;
import cn.shuibo.annotation.RequestCrypt;
import cn.shuibo.annotation.ResponseCrypt;
import cn.shuibo.bean.TestBean;
import cn.shuibo.config.MutiSecretKeyConfig;
import cn.shuibo.dto.ResponseBodyDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Author:Bobby
 * DateTime:2019/4/17 15:22
 **/
@RestController
public class TestController {

    @Autowired
    MutiSecretKeyConfig mutiSecretKeyConfig;

    /**
     * 对返回值加密
     * @return
     */
    @ResponseCrypt
    @GetMapping("/test01")
    public TestBean test01(){
        String name ="01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
        TestBean testBean = new TestBean();
        testBean.setName("12346");
        testBean.setAge(18);
        AdviceLocalThread.setAppid(new AdviceLocalThread.AppIdDto("666666","123456"));
        return testBean;
    }

    /**
     * 对传过来的加密参数进行解密
     * @param testBean
     * @return
     */
    @RequestCrypt
    @PostMapping("/test02")
    public Object test02(@RequestBody TestBean testBean, HttpServletRequest request){
        return ResponseBodyDTO.buildSuccess("处理完毕");
    }


    /**
     * 对传过来的加密参数进行解密
     * @param testBean
     * @return
     */
    @RequestCrypt
    @ResponseCrypt
    @PostMapping("/test03")
    public Object test03(@RequestBody TestBean testBean){
        return testBean;
    }

}
